package com.logistics.pick.entity.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.logistics.pick.entity.model.PickSave;
import com.logistics.utils.bean.UserBean;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 拣配单
 * </p>
 *
 * @author kaihan.wang
 * @since 2024-06-28
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("lgs_pick")
public class Pick implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    //单号
    private String code;

    //状态：0:拣配中,10:拣配完成,20:配送中,30:配送完成
    private Integer status;

    @TableField(select = false)
    private List<PickContainer> containers;

    //ERP领料单号
//    private String erpInvbillCode;

    //ERP单据类型（1:领料单，2:退料单）
//    private Integer erpInvbillType;

    //优先级
//    private Integer priority;

    // 创建人组织编码
    private String createOrgCode;

    // 创建人部门编码
    private String createDepCode;

    // 创建人
    private String creator;

    // 创建时间
    private Date createTime;

    // 修改人
    private String updater;

    // 修改时间
    private Date updateTime;

    public Pick(){}

    public Pick(PickSave save){
        this.id = StringUtils.isNotNull(save.getId()) ? Integer.parseInt(save.getId()) : null;
        this.code = save.getCode();
        this.status = StringUtils.isNotNull(save.getStatus()) ? Integer.parseInt(save.getStatus()) : null;
//        this.erpInvbillCode = save.getErpInvbillCode();
        this.createOrgCode = save.getCreateOrgCode();
        this.createDepCode = save.getCreateDepCode();
        this.creator = save.getCreator();
        this.createTime = new Date();
        this.updater = save.getUpdater();
        this.updateTime = new Date();
    }

    public static Pick build(PickSave save){
        return new Pick(save);
    }

    public static Pick build(String code, String status){
        Pick pick = new Pick();
        pick.setCode(code);
        pick.setStatus(Integer.parseInt(status));
        return pick;
    }

//    public static Pick build(Integer id, String erpInvBillCode){
//        Pick pick = new Pick();
//        pick.setId(id);
////        pick.setErpInvbillCode(erpInvBillCode);
//        return pick;
//    }
//
//    public static Pick build(String erpInBillCode, Integer priority, String erpInvBillType){
//        Pick pick = new Pick();
////        pick.setErpInvbillCode(erpInBillCode);
////        pick.setErpInvbillType(Integer.parseInt(erpInvBillType));
////        pick.setPriority(priority);
//        return pick;
//    }
//
    public static Pick build(String status){
        Pick pick = new Pick();
        pick.setStatus(Integer.parseInt(status));
        return pick;
    }
//
//    public static Pick build(String code, String status, String erpInvbillCode, Integer erpInvbillType, UserBean userBean){
//        Pick pick = new Pick();
//        pick.setCode(code);
//        pick.setStatus(Integer.parseInt(status));
////        pick.setErpInvbillCode(erpInvbillCode);
////        pick.setErpInvbillType(erpInvbillType);
//        pick.setCreateOrgCode(userBean.getOrganization());
//        pick.setCreateDepCode(userBean.getDep());
//        pick.setCreator(userBean.getAccount());
//        pick.setUpdater(userBean.getAccount());
//        pick.setCreateTime(new Date());
//        pick.setUpdateTime(new Date());
//        return pick;
//    }
}
